package com.zxy.ziems.server.energy.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.energy.pojo.dto.EnergyEfficiencyLibraryDTO;
import com.zxy.ziems.server.energy.pojo.param.EnergyEfficiencyCompareParam;
import com.zxy.ziems.server.energy.pojo.param.EnergyEfficiencyLibraryParam;
import com.zxy.ziems.server.energy.pojo.vo.EnergyEfficiencyCompareTypeVO;
import com.zxy.ziems.server.energy.pojo.vo.EnergyEfficiencyCompareVO;
import com.zxy.ziems.server.energy.pojo.vo.EnergyEfficiencyLibraryVO;
import com.zxy.ziems.server.energy.service.EnergyEfficiencyLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 能源指标管理
 */
@RestController
@RequestMapping("/api/energy/efficiency")
public class EnergyEfficiencyManagerController {

    @Autowired
    private EnergyEfficiencyLibraryService energyEfficiencyLibraryService;

    /**
     * 列表
     * @param param
     * @return
     */
    @GetMapping("/pageLibrary")
    public PageResult<EnergyEfficiencyLibraryVO> pageLibrary (EnergyEfficiencyLibraryParam param) {
        return energyEfficiencyLibraryService.page(param);
    }

    /**
     * 新增
     * @param dto
     * @return
     */
    @PostMapping("/addLibrary")
    public JsonResponse<Void> addLibrary (@Validated(EnergyEfficiencyLibraryDTO.Add.class) @RequestBody EnergyEfficiencyLibraryDTO dto) {
        energyEfficiencyLibraryService.add(dto);
        return JsonResponse.SUCCESS();
    }

    /**
     * 修改
     * @param dto
     * @return
     */
    @PostMapping("/modifyLibrary")
    public JsonResponse<Void> modifyLibrary (@Validated(EnergyEfficiencyLibraryDTO.Modify.class) @RequestBody EnergyEfficiencyLibraryDTO dto) {
        energyEfficiencyLibraryService.modify(dto);
        return JsonResponse.SUCCESS();
    }

    /**
     * 删除
     * @param dto
     * @return
     */
    @PostMapping("/removeLibrary")
    public JsonResponse<Void> removeLibrary (@Validated(EnergyEfficiencyLibraryDTO.Delete.class) @RequestBody EnergyEfficiencyLibraryDTO dto) {
        energyEfficiencyLibraryService.remove(dto.getId());
        return JsonResponse.SUCCESS();
    }

    /**
     * 设备能耗对比属性
     * @param param
     * @return
     */
    @GetMapping("/getDeviceTataType")
    public JsonResponse<List<EnergyEfficiencyCompareTypeVO>> getDeviceTataType(@Validated(EnergyEfficiencyCompareParam.SelectType.class) EnergyEfficiencyCompareParam param) {
        return JsonResponse.SUCCESS(energyEfficiencyLibraryService.getDeviceTataType(param));
    }

    /**
     * 设备能耗对比
     * @param param
     * @return
     */
    @PostMapping("/deviceCompare")
    public JsonResponse<EnergyEfficiencyCompareVO> deviceCompare(@Validated(EnergyEfficiencyCompareParam.SelectCompare.class) @RequestBody EnergyEfficiencyCompareParam param) {
        return JsonResponse.SUCCESS(energyEfficiencyLibraryService.deviceCompare(param));
    }
}
